{template 'common/header'}
<ul class="nav nav-tabs">
	<!--<li {if $status == 1 }class="active"{/if}>
        <a href="{php echo $this->createWebUrl('hexiao', array('status'=>1))}">关键词设置</a>
    </li>-->
	<li {if $status == 3 && $op == 'display'} class="active"{/if}>
        <a href="{php echo $this->createWebUrl('hexiao', array('status' => 3))}">核销员管理</a>
    </li>

    <li {if $status == 2 && $op == 'record'} class="active"{/if}>
   	    <a href="{php echo $this->createWebUrl('hexiao', array('status' => 2))}">核销记录</a>
    </li>

    {if $status == 3 && $op == 'post'}

    <li {if $status == 3 && $op == 'post'} class="active"{/if}>

        <a href="{php echo $this->createWebUrl('hexiao', array('status' => 3))}">编辑核销员</a>

    </li>

    {/if}

</ul>



{if $status == 1}

<div class="main">

    <form id="dataform" action="" method="post" class="form-horizontal form">

        <div class="panel panel-default">

            <div class="panel-heading">

                核销设置

            </div>

            <div class="panel-body">

                    <div class="form-group">

                       <label class="col-xs-12 col-sm-3 col-md-2 control-label">核销关键字</label>

                       <div class="col-sm-9 col-xs-12">

                           <input type="text" name="keyword" class="form-control" value="{$set['content']}" />

                           <span class='help-block'>店员核销使用，如果不填写默认为核销，使用方法: 回复关键词后系统会提示输入核销码</span>

                       </div>

                   </div>

                   <div class="form-group">

                           <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>

                           <div class="col-sm-9 col-xs-12">

                                 <input type="submit" name="keysubmit"  value="保存设置" class="btn btn-primary"/>

                                 <input type="hidden" name="token" value="{$_W['token']}" />

                           </div>

                    </div>

            </div>

        </div>

    </form>

</div>

{/if}

<!-- 核销记录 -->
{if $status==2}
<div class="main">
	<div class="panel panel-default">
		<div class="panel-heading">核销记录</div>
		<div class="panel-body">
			<div class="table-responsive panel-body">
				<table class="table table-hover table-bordered" style="min-width: 300px;" >
					<thead class="navbar-inner" style="">
						<tr >
							<th style="width:30px;text-align: center;">ID</th>
							<th style="width:110px;text-align: center;">核销名称</th>
							<th style="width:60px;text-align: center;">核销金额</th>
							<th style="width:110px;text-align: center;">核销人</th>
							<th style="width:110px;text-align: center;">被核销人</th>
							<th style="width:100px;text-align: center;">核销时间</th>
							<!--<th style="width:30px;text-align: center;">操作</th>-->
						</tr>
					</thead>
					<tbody style="text-align: center;">
						{loop $list $list}
						<tr>
							<td>{$list['id']}</td>
							<td>{$list['name']}</td>
							<td>{$list['discount']}</td>
							<td>{$list['personname']}</td>
							<td>{$list['usedpersonname']}</td>
							<td>{$list['time']}</td>
							
<!--							<td >
								<a href="" onclick="return confirm('此操作不可恢复，确认删除？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="删除"><i class="fa fa-times"></i>
							</a>
								<a href="{php echo $this->createWebUrl('showperiod', array('gid'=>$goods['id']));}" class="btn btn-success btn-sm" data-original-title="" title="">查看往期</a>
							</td>-->
						</tr>
						{/loop}
					</tbody>
				</table>
				{$pager}
			</div>
		</div>
	</div>
</div>
{/if}

{if $status==3}

	{if $op == 'post'}

		<div class="main">

		    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">

		        

		        <div class='panel panel-default'>

		            <div class='panel-heading'>

		                核销员设置

		            </div>

		            <div class='panel-body'>

		               

		                <div class="form-group">

		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 选择核销员</label>

		                    <div class="col-sm-9 col-xs-12">

		                        <input type='hidden' id='openid' name='openid' value="{$saler['openid']}" />

		                        <div class='input-group'>

		                            <input type="text" name="saler" maxlength="30" value="{if !empty($saler)}{$saler['nickname']}{/if}" id="saler" class="form-control" readonly />

		                            <div class='input-group-btn'>

		                                <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus').modal();">选择核销员</button>

		                            </div>

		                        </div>

		                        {if !empty($saler)}

		                        <span class='help-block'><img style="width:100px;height:100px;border:1px solid #ccc;padding:1px" src="{$saler['avatar']}" id="avatar" /></span>

		                        {/if}

		                        

		                        <div id="modal-module-menus"  class="modal fade" tabindex="-1">

		                            <div class="modal-dialog" style='width: 920px;'>

		                                <div class="modal-content">

		                                    <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择核销员</h3></div>

		                                    <div class="modal-body" >

		                                        <div class="row">

		                                            <div class="input-group">

		                                                <input type="text" class="form-control" name="keyword" value="" id="search-kwd" placeholder="请输入粉丝昵称" />

		                                                <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>

		                                            </div>

		                                        </div>

		                                        <div id="module-menus" style="padding-top:5px;"></div>

		                                    </div>

		                                    <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>

		                                </div>

		

		                            </div>

		                        </div>

		                    </div>

		                </div>

		                 <div class="form-group">

							<label class="col-xs-12 col-sm-3 col-md-2 control-label">核销商家选择</label>

							<div class="col-sm-9 col-xs-12 chks">

								<div class='input-group'>

									<input type="text" name="saler" maxlength="30" value="{loop $salers $saler} {$saler['nickname']}; {/loop}" id="saler" class="form-control" readonly />

									<div class='input-group-btn'>

										<button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus2').modal();">选择商家</button>

									</div>

								</div>

						

								<div style="margin-top:.5em;" class="input-group multi-audio-details clear-fix" id='stores'>

									{loop $stores $store}

									<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="{$store['id']}">

										<div class="input-group">

											<input type="hidden" value="{$store['id']}" name="storeids[]">

											<input type="text" value="{$store['name']}" readonly="" class="form-control">

											<div class="input-group-btn">

												<button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button>

											</div>

										</div>

									</div>

									{/loop}

								</div>

								<span class='help-block'>如果不选择商家，则此核销员为全局核销员，所有商家的均可核销</span>

						

								<div id="modal-module-menus2" class="modal fade" tabindex="-1">

									<div class="modal-dialog" style='width: 920px;'>

										<div class="modal-content">

											<div class="modal-header">

												<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>

												<h3>选择商家</h3></div>

											<div class="modal-body">

												<div class="row">

													<div class="input-group">

														<input type="text" class="form-control" name="keyword" value="" id="search-kwd2" placeholder="请输入商家名称" />

														<span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_stores();">搜索</button></span>

													</div>

												</div>

												<div id="module-menus2" style="padding-top:5px;"></div>

											</div>

											<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>

										</div>

						

									</div>

								</div>

							</div>

						

						</div>

		                

		                <div class="form-group">

		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>

		                    <div class="col-sm-9 col-xs-12">

		                        <label class='radio-inline'>

		                            <input type='radio' name='salerstatus' value=1 {if $saler['status']==1}checked{/if} /> 启用

		                        </label>

		                        <label class='radio-inline'>

		                            <input type='radio' name='salerstatus' value=0 {if $saler['status']==0}checked{/if} /> 禁用

		                        </label>

		                    </div>

		                </div>

		                

		                   <div class="form-group"></div>

		            <div class="form-group">

		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>

		                    <div class="col-sm-9 col-xs-12">

		                    		<input type="hidden" name="salerid" value="{$id}" />

		                    		<input type="hidden" name="status" value="{$status}" />

		                            <input type="submit" name="salersubmit" value="提交" class="btn btn-primary col-lg-1"  />

		                            <input type="hidden" name="token" value="{$_W['token']}" />

		                    </div>

		            </div>

		                

		            </div>

		        </div>

		   

		    </form>

		</div>

		<script language='javascript'>

		    $('form').submit(function () {

		        if ($(':input[name=saler]').isEmpty()) {

		            Tip.focus($(':input[name=saler]'), '请选择核销员!');

		            return false;

		        }

		        return true;

		    })

		</script>

	{elseif $op == 'display'}

		<form action="" method="post" onsubmit="return formcheck(this)">

		    <div class='panel panel-default'>

		        <div class='panel-heading'>

		          	  核销员管理

		        </div>

		        <div class='panel-body'>

		

		            <table class="table">

		                <thead>

		                    <tr>

		                        <th>核销员</th>

		                        <th>所属商家</th>

		                        <th>状态</th>

		                        <th>操作</th>

		                    </tr>

		                </thead>

		                <tbody>

		                    {loop $list $row}

		                    <tr>

		                        <td><img src="{$row['avatar']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc" id="avatar" /> {$row['nickname']}</td>

		                        <td>{if empty($row['storename'])}全店核销{else}{$row['storename']}{/if}</td>

		                        <td>

		                            {if $row['status']==1}

		                            <span class='label label-success'>启用</span>

		                            {else}

		                            <span class='label label-danger'>禁用</span>

		                            {/if}

		                        </td>

		                        <td>

		                            <a class='btn btn-default' href="{php echo $this->createWebUrl('hexiao', array('op' => 'post','status'=>$status,'id' => $row['id']))}"><i class='fa fa-edit'></i></a>

		                            <a class='btn btn-default'  href="{php echo $this->createWebUrl('hexiao', array('op' => 'delete','status'=>$status, 'id' => $row['id']))}" onclick="return confirm('确认删除此核销员吗？');

		                                    return false;"><i class='fa fa-remove'></i></a>

		                           </td>

		                    </tr>

		                    {/loop}

		

		                </tbody>

		            </table>

		

		        </div>

		        <div class='panel-footer'>

		            <a class='btn btn-default' href="{php echo $this->createWebUrl('hexiao', array('op' => 'post','status'=>$status))}"><i class="fa fa-plus"></i> 添加新核销员</a>

		        </div>

		    </div>

		</form>

	{/if}

	<script language='javascript'>

	     function search_members() {

	           if( $.trim($('#search-kwd').val())==''){

	                 Tip.focus('#search-kwd','请输入关键词');

	                 return;

	             }

			$("#module-menus").html("正在搜索....")

			$.get('{php echo $this->createWebUrl('hexiao',array('status'=>5))}', {

				keyword: $.trim($('#search-kwd').val())

			}, function(dat){

				$('#module-menus').html(dat);

			});

		}

		function select_member(o) {
			$("#openid").val(o.openid);
			$("#saler").val(o.nickname);
			$("#avatar").attr('src', o.avatar);
			$(".close").click();
		}
	    function search_stores() {
			$("#module-menus2").html("正在搜索....")
			$.get('{php echo $this->createWebUrl('hexiao',array('status'=>4))}', {
				keyword: $.trim($('#search-kwd2').val())
			}, function(dat){
				$('#module-menus2').html(dat);
			});
		}
		function remove_store(obj){
		        var storeid = $(obj).closest('.multi-audio-item').attr('storeid');
		        	$('.multi-audio-item[storeid="' + storeid +'"]').remove();
		    }
		function select_store(o) {
		                        if($('.multi-audio-item[storeid="' + o.id +'"]').length>0){
		                            return;
		                        }
		                        var html ='<div style="height: 40px; position:relative; float: left; margin-right: 18px;" class="multi-audio-item" storeid="' + o.id +'">';
		                html+='<div class="input-group">';
		                    html+='<input type="hidden" value="' + o.id +'" name="storeids[]">';
		                    html+='<input type="text" value="' + o.name +'" readonly="" class="form-control">';
		                    html+='<div class="input-group-btn"><button type="button" onclick="remove_store(this)" class="btn btn-default"><i class="fa fa-remove"></i></button></div>';
		             html+='</div></div>';
		                        $('#stores').append(html);
		 	}
	</script>
{/if}
{template 'common/footer'}